<form name="postform" action="<?php ?>/post.php" method="post" width="600px">
<?php
//include('functions.php');
//db();

if($_POST['postid'] && $_POST['postid']!=""){
	$postid = $_POST['postid'];
	$siteid = $site['id'];
	//echo $postid;
	if($postid > 0){ 
		$postqry = dbSelect('posts',array("id=$postid"));
		if(mysql_numrows($postqry)==1){
			$thispost = mysql_fetch_array($postqry);
			//echo $thispost['type_id']; 
			if($thispost['type_id'] >= 1){
				$post_type_qry = dbSelect('post_types',"","ORDER BY ord");	
				$typename = 'Post';
				if($thispost['type_id'] == 3){$typename = 'Prayer Request';}
				if($thispost['type_id'] == 4){$typename = 'People Need';}
				if($thispost['type_id'] == 5){$typename = 'Stuff Need';}
				if($thispost['type_id'] == 6){$typename = 'Money Need';}	
	
	$eventtypeqry = dbSelect('ddl_event_type',"","ORDER BY ord");
	$agegroupqry = dbSelect('ddl_agegroup',"","ORDER BY ord");
	$eventperqry = dbSelect('ddl_event_per',"","ORDER BY ord");
	$ccperqry = dbSelect('ddl_cc_per',"","ORDER BY ord");
	$cc_coordqry = dbSelect('sites_users',array("site_id=$siteid","usertype_id=3"));
	?>
	<!---
	<div class="posts" id="posts">
		<div class="post">
			<div class="post_title"><?php echo $posts['title']; ?></div>
			<span class="post_author"><?php echo $authorname; ?></span>&nbsp;<span id="post_body"><?php echo urldecode($posts['post']); ?></span>
			<div class="post_datetime"><?php if($nicetime){echo $nicetime;} ?></div>
		</div>
	</div>
	--->
<div id="posts" class="posts">
<div class="post_title"><?php echo $typename; ?> Details</div>
			<table>
				<tr><td align="right"><span class="inputlabel">Title:</span></td>
					<td colspan="3"><input class="largeprint" id="title" name="title" size="60" value="<?php if($thispost['title']){echo $thispost['title'];} ?>" /></td>
					</tr>
				<tr>	
				<td align="right"><span class="inputlabel">Type:</span></td>
					<td>
						<select id="type_id" name="type_id" class="largeprint" onclick="showPanel();">
							<option>--select option--</option>
								<?php
								while($post_type_row = mysql_fetch_array($post_type_qry)){
								if($thispost[type_id]==$post_type_row['id']){$selected = ' SELECTED ';}else{$selected = '';}
									echo '<option value="'.$post_type_row['id'].'" '.$selected.'>'.$post_type_row['type'].'</option>';
								}
								?>
						</select>
					</td>
				
					<td  align="right"><span class="inputlabel">Publish&nbsp;Date:</span>
					<input type="text" class="largeprint" id="publishdate" name="publishdate" size="9" value="<?php if($thispost['publishdate']!="0000-00-00"){echo date("m/d/Y",dateFormat($thispost['publishdate']));} ?>" /></td>
					<!---
					<td align="right">Author:</td>
					<td><select id="author_id" name="author_id"><option>--select option--</option></select></td>
					--->
				</tr>
				<tr>
					<td colspan="4">
						<textarea class="mceEditor" rows="7" style="width: 100%;"  id="postbody" name="postbody"><?php if($thispost['post']){echo urldecode($thispost['post']);} ?></textarea>
					</td>
				</tr>
			</table>
		</div>
<?php	} ?>
<!---events-------------------------------------------->
<?php	if($thispost['type_id']==2){ ?>
		<div id="event_post" class="post_section">
		<h2>Event Details</h2>
		<div class="editor_section">
			<table style="margin: 0px 0px 0px 0px;">
				<tr>
					<td><span class="inputlabel">Start:</span></td>
					<td>
					<table>
						<tr>
							<td><input type="text" id="startdate" name="startdate" size="7" value="<?php if($thispost['startdate']!="0000-00-00"){echo date("m/d/Y",dateFormat($thispost['startdate']));} ?>" /></td>
							<td>
							<?php 
								$starttime = $thispost['starttime'];
								$starttimearr = explode(':',$starttime);
								$starttime_hour = $starttimearr[0];
								$split2 = explode(' ',$starttimearr[1]);
								$starttime_min = $split2[0];
								$starttime_ampm = $split2[1];
								
								$endtime = $thispost['endtime'];
								$endtimearr = explode(':',$endtime);
								$endtime_hour = $endtimearr[0];
								$split3 = explode(' ',$endtimearr[1]);
								$endtime_min = $split3[0];
								$endtime_ampm = $split3[1];
							?>
								<select id="starthour" name="starthour">
								<?php 
								for($i=1;$i < 13;$i++){
									if($starttime_hour==$i){$selected = ' SELECTED ';}else{$selected = '';}
									echo '<option value="'.$i.'" '.$selected.'>'.$i.'</option>';
								}
								?>
								</select>
							</td>
							<td>
								<select id="startmin" name="startmin">
									<option value="00" <?php if($starttime_min=='00'){echo ' SELECTED ';} ?>>00</option>
									<option value="15" <?php if($starttime_min=='15'){echo ' SELECTED ';} ?>>15</option>
									<option value="30" <?php if($starttime_min=='30'){echo ' SELECTED ';} ?>>30</option>
									<option value="45" <?php if($starttime_min=='45'){echo ' SELECTED ';} ?>>45</option>
								</select>
							</td>
							<td>
								<select id="startampm" name="startampm">
									<option value="am" <?php if($starttime_ampm=='am'){echo ' SELECTED ';} ?>>am</option>
									<option value="pm" <?php if($starttime_ampm=='pm'){echo ' SELECTED ';} ?>>pm</option>
								</select>
							</td>
						</tr>
						</table>
					</td>
					<td align="right">
						<span class="inputlabel">End:</span>
					</td>
					<td>
					<table>
						<tr>
							<td><input type="text" id="enddate" name="enddate" size="7" value="<?php if($thispost['enddate']!="0000-00-00"){echo date("m/d/Y",dateFormat($thispost['enddate']));} ?>" /></td>
							<td>
								<select id="endhour" name="endhour">
								<?php 
								for($i=1;$i < 13;$i++){
									if($endtime_hour==$i){$selected = ' SELECTED ';}else{$selected = '';}
									echo '<option value="'.$i.'" '.$selected.'>'.$i.'</option>';
								}
								?>
								</select>
							</td>
							<td>
								<select id="endmin" name="endmin">
									<option value="00" <?php if($endtime_min=='00'){echo ' SELECTED ';} ?>>00</option>
									<option value="15" <?php if($endtime_min=='15'){echo ' SELECTED ';} ?>>15</option>
									<option value="30" <?php if($endtime_min=='30'){echo ' SELECTED ';} ?>>30</option>
									<option value="45" <?php if($endtime_min=='45'){echo ' SELECTED ';} ?>>45</option>
								</select>
							</td>
							<td>
								<select id="endampm" name="endampm">
									<option value="am" <?php if($endtime_ampm=='am'){echo ' SELECTED ';} ?>>am</option>
									<option value="pm" <?php if($endtime_ampm=='pm'){echo ' SELECTED ';} ?>>pm</option>
								</select>
							</td>
						</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<span class="inputlabel">Type:</span></td>
					<td>
					<select id="event_type" name="event_type"><option>--select option--</option>
					<?php
						while($eventtyperow = mysql_fetch_array($eventtypeqry)){
							if($thispost[type_id]==$eventtyperow['id']){$selected = ' SELECTED ';}else{$selected = '';}
								echo '<option value="'.$eventtyperow['id'].'" '.$selected.'>'.$eventtyperow['type'].'</option>';
							}
					?>
					</select>
					</td>
					<td align="right">
					<span class="inputlabel">Ages:</span>
					</td>
					<td>
					<select id="event_agegroup" name="event_agegroup"><option>--select option--</option>
					<?php
						while($agegrouprow = mysql_fetch_array($agegroupqry)){
							if($thispost[type_id]==$agegrouprow['id']){$selected = ' SELECTED ';}else{$selected = '';}
								echo '<option value="'.$agegrouprow['id'].'" '.$selected.'>'.$agegrouprow['agegroup'].'</option>';
							}
					?>
					</select>
					</td>
				</tr>
				<tr>
					<td><span class="inputlabel">Cost:</span></td>
					<td colspan="3"><span class="inputlabel">$</span><input id="event_cost" name="event_cost" size="5" value="<?php if($thispost['event_cost']){echo $thispost['event_cost'];} ?>" />
					<select id="event_per" name="event_per">
					<option>--select--</option>
					<?php
						while($eventperrow = mysql_fetch_array($eventperqry)){
							if($thispost[type_id]==$eventperrow['id']){$selected = ' SELECTED ';}else{$selected = '';}
								echo '<option value="'.$eventperrow['id'].'" '.$selected.'>'.$eventperrow['per'].'</option>';
							}
					?>
					</select></td>
				</tr>
				<tr>
					<td colspan="4">
						<span class="inputlabel">Is event on-site?</span>
						<?php yesNoDdl('event_isonsite',1); ?>
						<br />
						<small>(a map link will be created for you.)</small>
					</td>
				</tr>
				<tr>
					<td colspan="4">
						<div id="eventaddr" class="post_subsection" style="display: none;">
						<br />
						<h2>Event Location</h2>
							<table>
								<tr>
									<td><span class="inputlabel">Address:</span></td><td><input type="text" id="event_addr" name="event_addr" size="30" value="<?php if($thispost['event_addr']){echo $thispost['event_addr'];} ?>" /></td>
								</tr>
								<tr>
									<td><span class="inputlabel">Address2:</span></td><td><input type="text" id="event_addr2" name="event_addr2" size="30" /></td>
								</tr>
								<tr>
									<td><span class="inputlabel">City,&nbsp;St,&nbsp;Zip:</span></td>
									<td>
										<input type="text" id="event_city" name="event_city" size="15" value="<?php if($thispost['event_city']){echo $thispost['event_city'];} ?>" />
										<input type="text" id="event_state" name="event_state" style="width: 30px;" value="<?php if($thispost['event_state']){echo $thispost['event_state'];} ?>" />
										<input type="text" id="event_zip" name="event_zip" style="width: 50px;" value="<?php if($thispost['event_zip']){echo $thispost['event_zip'];} ?>" />
									</td>
								</tr>
							</table>
						</div>
						<br />
					</td>
				</tr>
				<tr><td colspan="4"><h2>Childcare Details:</h2></td></tr>
				<tr>
					<td colspan="2">
						<span class="inputlabel">Children&nbsp;welcome <small>(in event)</small>? </span>
						<?php yesNoDdl('event_childrenwelcome',0); ?>
					</td>
					<td colspan="2">
						<span class="inputlabel">Childcare available?</span>
						<?php yesNoDdl('event_ischildcare',0); ?>
					</td>
				</tr>
			</table>
<!---/events-------------------------------------------->
<br />
<!---childcare-------------------------------------------->
			<div id="childcare_post" class="post_subsection" style="display: none;">
			<table style="margin: 0px 0px 0px 0px;">
				<tr>
					<td><span class="inputlabel">Childcare coordinator:</span></td>
					<td align="left">
						<select id="cc_coordinator_id" name="cc_coordinator_id">
							<option>--select option--</option>
							<?php
							while($cc_coordrow = mysql_fetch_array($cc_coordqry)){
								if($thispost[type_id]==$cc_coordrow['id']){$selected = ' SELECTED ';}else{$selected = '';}
								echo '<option value="'.$cc_coordrow['id'].'" '.$selected.'>'.$cc_coordrow['usertype'].'</option>';
							}
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td><span class="inputlabel">Childcare&nbsp;cost:</span></td>
					<td colspan="3">
						<span class="inputlabel">$</span><input id="cc_cost" name="childcare_cost" size="5" />
						<select id="cc_per" name="cc_per">
							<option>--select--</option>
					<?php
						while($ccperrow = mysql_fetch_array($ccperqry)){
							if($thispost[type_id]==$ccperrow['id']){$selected = ' SELECTED ';}else{$selected = '';}
								echo '<option value="'.$ccperrow['id'].'" '.$selected.'>'.$ccperrow['ccper'].'</option>';
							}
					?>
						</select>
					</td>
				</tr>
				<tr>
					<td colspan="4">
						<span class="inputlabel">Is childcare on-site?</span>			
						<?php yesNoDdl('cc_isonsite',1); ?>
						<br /><small>(a map link will be created for you.)</small>
					</td>
				</tr>
				<tr><td colspan="4"></td></tr>
				<tr>
					<td colspan="4">
						<div id="ccaddr" class="post_subsection" style="display: none;">
						<br />
						<h2>Childcare Location:</h2>
							<table>
								<tr>
									<td><span class="inputlabel">Address:</span></td><td><input type="text" id="cc_addr" name="c_addr" size="30" /></td>
								</tr>
								<tr>
									<td><span class="inputlabel">Address2:</span></td><td><input type="text" id="cc_addr2" name="c_addr2" size="30" /></td>
								</tr>
								<tr>
									<td><span class="inputlabel">City,&nbsp;St,&nbsp;Zip:</span></td>
									<td>
										<input type="text" id="cc_city" name="cc_city" size="15" />
										<input type="text" id="cc_state" name="cc_state" style="width: 30px;" />
										<input type="text" id="cc_zip" name="cc_zip" style="width: 50px;" />
									</td>
								</tr>
							</table>
						</div>
					</td>
				</tr>
			</table>
			</div><!---/childcare_post--->
			</div><!---/editor_section--->
		</div>
<!---/childcare-------------------------------------------->
<?php } ?>
<?php	if($thispost['type_id'] >= 3 && $thispost['type_id'] <= 6){ ?>
<!---needs-------------------------------------------->
		<div id="need_post" class="post_section">
		<div class="editor_section">
			<span class="inputlabel">Cost:</span>
			<span class="inputlabel">$</span><input type="text" class="largeprint" id="need_cost" size="7" name="need_cost" value="<?php if($thispost['need_cost']){echo $thispost['need_cost'];} ?>" />
			<br /><br />
			<div class="post_title">Needs Contact</div></h2><span class="inputlabel">Name:</span>
			<input type="text" id="contactname" name="contactname" class="largeprint" size="30" value="<?php if($thispost['contactname']){echo $thispost['contactname'];} ?>" />
			<br />
			<span class="inputlabel">Email:</span>
			<input type="text" id="contactemail" name="contactemail" class="largeprint" size="30" value="<?php if($thispost['contactemail']){echo $thispost['contactemail'];} ?>" />
			<br />
			<span class="inputlabel">Phone:</span>
			<input type="text" id="contactphone" name="contactphone" class="largeprint" size="30" value="<?php if($thispost['contactphone']){echo $thispost['contactphone'];} ?>" />
			<br /><br />
			<div class="post_title">God's Answer</div>
							<table style="margin: 0px 0px 0px 0px;">
								<tr>
									<td colspan="4"><span class="inputlabel">Date answered:</span><input type="text" id="need_answereddate" class="largeprint" name="need_answereddate" value="<?php if($thispost['need_answereddate']){echo date('m/d/Y',dateformat($thispost['need_answereddate']));} ?>" /></td>
								</tr>
								<tr>
									<td colspan="4">
										<span class="inputlabel">How did God answer?</span><br />
										<textarea class="mceEditor" id="need_answer" name="need_answer"><?php if($thispost['need_answer']){echo $thispost['need_answer'];} ?></textarea>
									</td>
								</tr>
							</table>
			</div><!---/editor_section--->
		</div>
<!---/needs-------------------------------------------->
		<?php } ?>
	</td>
	</tr>
	<tr>
		<td colspan="4" align="right">
			<input type="submit" id="submit" name="submit" value="Save" />
		</td>
	</tr>
</table>
</div>
<?php		
		}
	}
}
?>
</form>